﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace Landscape.Elements
{
    internal class Parameter
    {
        public string Name;
        public string Value;

        public Parameter(XmlNode node)
        {
            XmlNode nameAttributeNode = node.Attributes.GetNamedItem("name");

            if (nameAttributeNode == null || nameAttributeNode.Value.Trim().Length == 0)
            {
                throw new XmlNodeException("Attribute 'name' is missing or empty.", node);
            }

            Name = nameAttributeNode.Value.Trim();

            XmlNode valueAttributeNode = node.Attributes.GetNamedItem("value");

            if (valueAttributeNode != null && valueAttributeNode.Value.Length > 0) { 
                Value = valueAttributeNode.Value.Trim();
            }
            else if (node.InnerXml.Length > 0)
            {
                Value = node.InnerXml.Trim();
            }
            else {
                Value = string.Empty;
            }
        }
    }
}
